// pages/updateuser/updateuser.js
Page({
  data: {

    dialog4: {
      hidden: true
    },
    dialog5: {
      hidden: true
    },
    id:{

    },
    dialog2: { hidden: true },
    dialog3: { hidden: true },
    ynameHidden: { hidden: true },
    yphoneHidden: { hidden: true },
    yfilenameHidden: { hidden: true },
    ydetailedHidden: { hidden: true },
    yfangjianhao: { hidden: true },
    yaddressHidden: { hidden: true },
    imageHidden: { hidden: true },
    systemHidden: { hidden: true },
    longlatitudeHidden: { hidden: true },
    yfangjianhao2: { hidden: true },
    upload: { hidden: true },
    loHidden: { hidden: true }
  },
 
  

  onLoad: function (options) {
 
    // 页面初始化 options为页面跳转所带来的参数
    var yid = options.id;
    this.setData({
      id: yid,
    })
    //wx.request({
     // url: 'https://wwl.ycws.cc/ssm/uploadfile/wxselectfile?id=' + yid,
      //success: function (res) {
       // page.setData({ list: res.data.uploads })
       // console.log(res.data)
     // }
   // })
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  //图片选择1
  uploads: function () {
    var that = this;
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['compressed'],
      //sizeType: ['original', 'compressed'],   // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'],         // 可以指定来源是相册还是相机，默认二者都有
      success: function (res1) {

        that.setData({ 'dialog4.hidden': false });
        console.log(res1.tempFilePaths[0])
        wx.uploadFile({
          url: 'https://wwl.ycws.cc/ssm/face/image',
          //url: 'http://localhost:9090/ssm/face/image',
          filePath: res1.tempFilePaths[0],
          name: 'filename',
          success: function (res) {
            console.log(res.data);
            var s = JSON.parse(res.data);
            var mes = s.error_message;
            if (mes == "CONCURRENCY_LIMIT_EXCEEDED") {
              console.log("图片上传有误，请重试");
              that.setData({ 'systemHidden.hidden': false });
              that.setData({ 'dialog4.hidden': true })
            } if (s.faces.length == 0) {
              console.log("不是人脸图片");
              that.setData({ 'imageHidden.hidden': false });
              that.setData({ 'dialog4.hidden': true })
            } else if (s.faces.length >= 1) {
              console.log("是人脸图片");
              that.setData({ 'dialog4.hidden': true })
              console.log(res1.tempFilePaths[0])
              that.setData({
                userphoneurl: res1.tempFilePaths[0],
              })
            }
          }
        })
      }
    })
  },

  //更新图片
  upusertophone: function (e) {
  var thisto = this;
  var id = this.data.id;
  var yfilename = this.data.userphoneurl;
  if (yfilename == undefined) {
    this.setData({ 'yfilenameHidden.hidden': false });
  }else{
    var arrName = [];
    arrName.push("file_pic1");

    var arrURL = [];
    arrURL.push(yfilename);

    var filename = arrName[b];
    var b = 0;

    var filePath = arrURL[b].toString();
    var filename = arrName[b];
    wx.uploadFile({
      url: "https://wwl.ycws.cc/ssm/uploadfile/addfile3",
      //url: "http://localhost:9090/ssm/uploadfile/addfile3",
      filePath: filePath, //这是文件url
      name: 'filename',   //这是表示当前文件的name
      header: { "Content-Type": "multipart/form-data" },
      formData: {
        filePath: filePath,
        yid: id
      },
      success: function (res) {
        
        var s = JSON.parse(res.data);
        if (s.code == "00") {
          var ynumbertwo = wx.getStorageSync("ynumbertwo");
          wx.navigateTo({
            url: '../../pages/newshowuser/newshowuser?ynumber=' + ynumbertwo
          })
        } else {
          console.log("出现异常")
          this.setData({ 'systemHidden.hidden': false });
        }

      },
      fail: function (res) {//连不上服务，数据查询异常给予提示
        
        thisto.setData({ 'loHidden.hidden': false });
        console.log("连接失败")
      }
    })
  }
  },
  //提示语句
  loChange: function (e) {
    this.setData({
      loHidden: {
        hidden: true
      }
    });
  },
  //提示语句
  systemChange: function (e) {
    this.setData({
      systemHidden: {
        hidden: true
      }
    });
  },
  //提示语句
  yfilenameChange: function (e) {
    this.setData({
      yfilenameHidden: {
        hidden: true
      }
    });
  },
  //提示语句
  imageChange: function (e) {
    this.setData({
      imageHidden: {
        hidden: true
      }
    });
  }
})